package com.zat.mes.andrmes.dofun.system.vm

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.love.zywanandroid.retrofit.RetrofitManager
import com.love.zywanandroid.retrofit.api.ApiService
import com.zat.mes.andrmes.data.BaseResponse
import com.zat.mes.andrmes.data.ComResultBean
import com.zat.mes.andrmes.retrofit.callback.MesCallBack
import retrofit2.Call
import retrofit2.Response

/**
 * @author zy
 * @date :2020-02-07 00:05
 * @description:
 */
class LoginViewModel : ViewModel() {


    private val comData: MutableLiveData<List<ComResultBean>> by lazy {
        MutableLiveData<List<ComResultBean>>().also {
            loadComList()
        }
    }

    fun getComList(): LiveData<List<ComResultBean>> {
        return comData
    }

    /**
     * 获取公司列表
     */
    private fun loadComList() {
        RetrofitManager.run {
            apiService(ApiService::class.java).getCom()
                .enqueue(object : MesCallBack<BaseResponse<List<ComResultBean>>>() {
                    override fun onSuccessful(
                        call: Call<BaseResponse<List<ComResultBean>>>?,
                        response: Response<BaseResponse<List<ComResultBean>>>?
                    ) {
                        var comResultBeanList = response?.body()?.result
                        comData.postValue(comResultBeanList)
                    }

                })
        }
    }


}